package com.java.IO.object_stream;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

public class ObjectOutputStreamAPI {
    public static void main(String[] args) throws IOException {
        String path = "File和IO流\\com\\java\\files\\byte_stream.txt";
        
        // 创建对象：创建规则主要依赖于构造形参OutputStream的子类
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(path));
        
        // writeXxx：写出Java对象到目的地
        objectOutputStream.writeObject(new Student("SYX", 19, Student.Sex.BOY));
        objectOutputStream.writeObject(new Student("LYW", 18, Student.Sex.BOY));
        
        // close：关闭流并释放资源，若此前未执行flush则充当部分flush作用将缓冲区数据写出到目标地
        objectOutputStream.close();
    }
}
